package model.entities;

import java.util.Collection;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import model.persistence.HibernateSessionFactory;

import org.hibernate.Session;

@Entity
@Table(name = "Empleados")
public class Empleado
{
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int id;
	
	@ManyToMany
	@JoinTable(name = "Empleados_Roles", joinColumns = { @JoinColumn(name = "idEmpleado", nullable = false) }, inverseJoinColumns = { @JoinColumn(name = "idRol", nullable = false) })
	private Collection<Rol> roles;

	@Column(name = "nombre", nullable = false)
	private String nombre;

	@Column(name = "apellido", nullable = false)
	private String apellido;

	@Column(name = "username", nullable = false)
	private String username;

	@Column(name = "password", nullable = false)
	private String password;

	public static void Save(Empleado empleado)
	{
		Session session = HibernateSessionFactory.getSessionFactory().openSession();
		session.save(empleado);
		session.flush();
		session.close();
	}

	public boolean autenticar(String pwd)
	{
		return password.equals(pwd);
	}

	public int getId()
	{
		return id;
	}

	public void setId(int id)
	{
		this.id = id;
	}

	public Collection<Rol> getRoles()
	{
		return roles;
	}

	public void setRoles(Collection<Rol> roles)
	{
		this.roles = roles;
	}

	public String getNombre()
	{
		return nombre;
	}

	public void setNombre(String nombre)
	{
		this.nombre = nombre;
	}

	public String getApellido()
	{
		return apellido;
	}

	public void setApellido(String apellido)
	{
		this.apellido = apellido;
	}

	public String getUsername()
	{
		return username;
	}

	public void setUsername(String username)
	{
		this.username = username;
	}

	public String getPassword()
	{
		return password;
	}

	public void setPassword(String password)
	{
		this.password = password;
	}

	public static Collection<Empleado> getEmpleados(Collection<Integer> empleados)
	{
		// TODO Auto-generated method stub
		return null;
	}
}
